package com.ftwj.demo.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;

/**
 * 
*
* <p>Title: MybatisPlusConfig</p>  
* <p>Description: MybatisPlus配置</p>
* <p>Copyright: Copyright (c) 2020 </p>  
* <p>Company: 兰州飞天网景信息产业有限公司</p>    
* @author WangSLi
* @date 2020年2月14日 下午5:16:12
* @version V1.0
 */
@EnableTransactionManagement//开启事务支持
@Configuration
@MapperScan("com.ftwj.**.dao")
@EntityScan("com.ftwj.**.entity")
public class MybatisPlusConfig {
	
	/**
     * mybatis-plus SQL执行效率插件【生产环境可以关闭】
     */
    @Bean({"dev"})
    public PerformanceInterceptor performanceInterceptor() {
        return new PerformanceInterceptor();
    }

    /**
     * 	分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        // paginationInterceptor.setLimit(你的最大单页限制数量，默认 500 条，小于 0 如 -1 不受限制);
        return paginationInterceptor;
    }
    
    /**
     * 	逻辑删除拦截器
     */
    @Bean
    public ISqlInjector sqlInjector() {
        return new LogicSqlInjector();
    }
    
    /**
     * 
     * <p>Title: mybatisConfigurationCustomizer</p>  
     * <p>Description: 配置返回Map时也转换未驼峰命名</p>  
     * @return 
     * @author WangSLi
     * @date 2020年5月7日  
     * @version 1.0
     */
    @Bean
	public ConfigurationCustomizer mybatisConfigurationCustomizer(){
    	return new ConfigurationCustomizer() {
			@Override
			public void customize(org.apache.ibatis.session.Configuration configuration) {
				configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
			}
		};
	}
    
    /**
     * 配置Mybatis读写分离
     * 
     */
    /*
    @Bean
    public MasterSlaveAutoRoutingPlugin masterSlaveAutoRoutingPlugin(){
        return new MasterSlaveAutoRoutingPlugin();
    }
    */
}
